#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\GPT.h>



static void *storeFromStruct;

static int recordNum;
void registerGPT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadGPTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerGPT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(GPT_FILENAME, SIZE_GPT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreGPTRecFromStruct(void *vdStruct)
{
	registerGPT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetGPTRec(), vdStruct, SIZE_GPT_REC);

}

void vdCopyGPTRecFromStruct(void *vdStruct)
{
	registerGPT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetGPTRec(), SIZE_GPT_REC);

}

int	inSaveGPTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerGPT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(GPT_FILENAME, SIZE_GPT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateGPTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerGPT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(GPT_FILENAME, SIZE_GPT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

char* szGetGPRSModelNoFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetGPRSModelNo();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->szGPRSModelNo;
}

void vdSetGPRSModelNoFromStruct(const char* szGPRSModelNo, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetGPRSModelNo(szGPRSModelNo);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((GPT_REC*)vdStruct)->szGPRSModelNo, szGPRSModelNo, sizeof(((GPT_REC*)NULL)->szGPRSModelNo)-1);
}

char* szGetUsernameFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetUsername();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->szUsername;
}

void vdSetUsernameFromStruct(const char* szUsername, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetUsername(szUsername);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((GPT_REC*)vdStruct)->szUsername, szUsername, sizeof(((GPT_REC*)NULL)->szUsername)-1);
}

char* szGetPasswordFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetPassword();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->szPassword;
}

void vdSetPasswordFromStruct(const char* szPassword, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetPassword(szPassword);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((GPT_REC*)vdStruct)->szPassword, szPassword, sizeof(((GPT_REC*)NULL)->szPassword)-1);
}

char* szGetTerminalIPFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetTerminalIP();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->szTerminalIP;
}

void vdSetTerminalIPFromStruct(const char* szTerminalIP, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTerminalIP(szTerminalIP);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((GPT_REC*)vdStruct)->szTerminalIP, szTerminalIP, sizeof(((GPT_REC*)NULL)->szTerminalIP)-1);
}

char* szGetSubNetMask1FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetSubNetMask1();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->szSubNetMask1;
}

void vdSetSubNetMask1FromStruct(const char* szSubNetMask1, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetSubNetMask1(szSubNetMask1);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((GPT_REC*)vdStruct)->szSubNetMask1, szSubNetMask1, sizeof(((GPT_REC*)NULL)->szSubNetMask1)-1);
}

char* szGetAPNFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetAPN();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->szAPN;
}

void vdSetAPNFromStruct(const char* szAPN, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetAPN(szAPN);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((GPT_REC*)vdStruct)->szAPN, szAPN, sizeof(((GPT_REC*)NULL)->szAPN)-1);
}

char* szGetPhoneNoGprsFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetPhoneNoGprs();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->szPhoneNoGprs;
}

void vdSetPhoneNoGprsFromStruct(const char* szPhoneNoGprs, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetPhoneNoGprs(szPhoneNoGprs);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((GPT_REC*)vdStruct)->szPhoneNoGprs, szPhoneNoGprs, sizeof(((GPT_REC*)NULL)->szPhoneNoGprs)-1);
}

char* szGetPrevT2DataFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetPrevT2Data();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->szPrevT2Data;
}

void vdSetPrevT2DataFromStruct(const char* szPrevT2Data, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetPrevT2Data(szPrevT2Data);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((GPT_REC*)vdStruct)->szPrevT2Data, szPrevT2Data, sizeof(((GPT_REC*)NULL)->szPrevT2Data)-1);
}

VS_BOOL fGetForceRebootFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetForceReboot();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->fForceReboot;
}

void vdSetForceRebootFromStruct(VS_BOOL fForceReboot, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetForceReboot(fForceReboot);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((GPT_REC*)vdStruct)->fForceReboot = fForceReboot;
}

VS_BOOL fGetTrack2EncryptFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetTrack2Encrypt();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->fTrack2Encrypt;
}

void vdSetTrack2EncryptFromStruct(VS_BOOL fTrack2Encrypt, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTrack2Encrypt(fTrack2Encrypt);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((GPT_REC*)vdStruct)->fTrack2Encrypt = fTrack2Encrypt;
}

VS_BOOL fGetHexHeaderFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetHexHeader();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->fHexHeader;
}

void vdSetHexHeaderFromStruct(VS_BOOL fHexHeader, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetHexHeader(fHexHeader);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((GPT_REC*)vdStruct)->fHexHeader = fHexHeader;
}

VS_BOOL fGetReserved5FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetReserved5();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->fReserved5;
}

void vdSetReserved5FromStruct(VS_BOOL fReserved5, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetReserved5(fReserved5);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((GPT_REC*)vdStruct)->fReserved5 = fReserved5;
}

VS_BOOL fGetReserved4FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetReserved4();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->fReserved4;
}

void vdSetReserved4FromStruct(VS_BOOL fReserved4, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetReserved4(fReserved4);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((GPT_REC*)vdStruct)->fReserved4 = fReserved4;
}

VS_BOOL fGetReserved3FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetReserved3();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->fReserved3;
}

void vdSetReserved3FromStruct(VS_BOOL fReserved3, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetReserved3(fReserved3);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((GPT_REC*)vdStruct)->fReserved3 = fReserved3;
}

VS_BOOL fGetReserved2FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetReserved2();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->fReserved2;
}

void vdSetReserved2FromStruct(VS_BOOL fReserved2, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetReserved2(fReserved2);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((GPT_REC*)vdStruct)->fReserved2 = fReserved2;
}

VS_BOOL fGetReserved1FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetReserved1();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((GPT_REC*)vdStruct)->fReserved1;
}

void vdSetReserved1FromStruct(VS_BOOL fReserved1, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetReserved1(fReserved1);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((GPT_REC*)vdStruct)->fReserved1 = fReserved1;
}

